<?php

require_once('MySugarApplication.php');
session_start();


$params = array('user_name' => $_REQUEST["username"],
                'password'  => $_REQUEST["password"],
                'version'   => '.01');

$result = $proxy->login($params,'MyApp');
$sess= $result['error']['number']==0 ? $result['id'] : null;

error_log($sess);

if($sess==''){
        $_SESSION["status"] = "loginfailed";
        $url = "Location: ".$app->appRoot."login.php";
} else {

        $_SESSION["authenticated_user_id"] = $_POST["username"];
        $_SESSION["sugar_session_id"] = $sess;
        $_SESSION["unique_key"] = $server_unique_key;;

        $redirect_url = $_SESSION["redirect_url"];
        if ($redirect_url == "")
                $redirect_url = $app->appRoot."library.php";

        $url = 'Location: '.$redirect_url;
}

header($url);

?>
